const app = getApp();
import * as profitTypes from '../../../../common/code/pickerList/profitType';
import * as network_utils from '../../../../http/NetworkUtils';
import * as constants from '../../../../common/Constants';
import * as umfutils from '../../../../utils/UmfUtils';

const BusScene = {
    SCENE_NOPOSS: "0",
    SCENE_POSS: "1"
};
Page({

    data: {
        //查询月份
        profitDate: '',

        profitAmt: _getProfitAmt(),
        tradeAmt: _getTradeAmt(),
        profitDetail: _getProfitDetail()
    },

    onLoad: function (options) {
        this.setData({
            profitDate: options.profitDate
        });

        wx.setNavigationBarTitle({
            title: "分润查询(" + options.profitDate + ")"
        });

        this._requestNPos();
    },

    tapDetail: function (event) {
        let profitType = event.currentTarget.dataset.tag;
        wx.navigateTo({
            url: '../profitQueryFilter/profitQueryFilter?profitType=' + profitType
            + "&date=" + this.data.profitDate
            + "&from=npos"
        });
        // wx.navigateTo({
        //     url: './nposDetails/nposDetails?profitType=' + profitType + "&date=" + this.data.profitDate
        // });
    },

    /**
     * 查询非POS汇总数据
     * @private
     */
    _requestNPos() {
        // let params = {
        //     types: "0",
        //     date: "201502"
        // };
        let params = {
            date: this.data.profitDate
        };

        network_utils.buildRequest(constants.Interfaces.FUNC_SN_POS_OR, params, {
            doHttpSucess: (response) => {
                if (constants.RetCodes.SUCCESS === response.retCode) {
                    this.setData({
                        profitAmt: _getProfitAmt(response),
                        tradeAmt: _getTradeAmt(response),
                        profitDetail: _getProfitDetail(response["productList"])
                    });
                    return true;
                }
                return false;
            }
        }).send();
    },
});

function _getProfitAmt(response) {
    let result = [];
    result.push({
        title: "全额分润金额(元)",
        value: response && response["fullProfitAmt"] ? umfutils.fentoyuan(response["fullProfitAmt"]) : "0.00"
    });
    result.push({
        title: "实际分润金额(元)",
        value: response && response["profitAmt"] ? umfutils.fentoyuan(response["profitAmt"]) : "0.00"
    });
    return result;
}

function _getTradeAmt(response) {
    let result = [];

    let remark = "";
    if (response && response["remark"]) {
        let remarkArr = response["remark"].split("~");
        if (remarkArr.length === 2) {
            remark = umfutils.fentoyuan(remarkArr[0]) + "~" + umfutils.fentoyuan(remarkArr[1]);
        } else {
            remark = response["remark"];
        }
    }


    result.push({
        title: "总交易额(元)",
        value: response && response["amount"] ? umfutils.fentoyuan(response["amount"]) : "0.00"
    });
    result.push({
        title: "交易总额区间(元)",
        value: remark ? remark : "0.00-0.00"
    });
    result.push({
        title: "交易总额分润系数",
        value: response && response["profitRate"] ? response["profitRate"] : "0.00"
    });
    return result;
}

function _getProfitDetail(response) {
    let result = [];
    if (response) {
        response["qPayAlipay"] && result.push({
            title: constants.ProfitTypes.QPAY_ALIPAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.QPAY_ALIPAY.name,
            value: umfutils.fentoyuan(response["qPayAlipay"])
        });
        response["qPayWePay"] && result.push({
            title: constants.ProfitTypes.QPAY_WEPAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.QPAY_WEPAY.name,
            value: umfutils.fentoyuan(response["qPayWePay"])
        });
        response["companyPay"] && result.push({
            title: constants.ProfitTypes.COMPANY_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.COMPANY_PAY.name,
            value: umfutils.fentoyuan(response["companyPay"])
        });
        response["officialAccPay"] && result.push({
            title: constants.ProfitTypes.OFFICIAL_ACC_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.OFFICIAL_ACC_PAY.name,
            value: umfutils.fentoyuan(response["officialAccPay"])
        });
        response["debitCardQPay"] && result.push({
            title: constants.ProfitTypes.DEBITCARD_QPAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.DEBITCARD_QPAY.name,
            value: umfutils.fentoyuan(response["debitCardQPay"])
        });
        response["creditCardQPay"] && result.push({
            title: constants.ProfitTypes.CREDITCARD_QPAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.CREDITCARD_QPAY.name,
            value: umfutils.fentoyuan(response["creditCardQPay"])
        });
        response["perObankPay"] && result.push({
            title: constants.ProfitTypes.PER_OBANK_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.PER_OBANK_PAY.name,
            value: umfutils.fentoyuan(response["perObankPay"])
        });
        response["enterOBankPay"] && result.push({
            title: constants.ProfitTypes.ENTER_OBANK_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.ENTER_OBANK_PAY.name,
            value: umfutils.fentoyuan(response["enterOBankPay"])
        });
        response["weAppPay"] && result.push({
            title: constants.ProfitTypes.WEAPP_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.WEAPP_PAY.name,
            value: umfutils.fentoyuan(response["weAppPay"])
        });
        response["weScanpay"] && result.push({
            title: constants.ProfitTypes.WESCAN_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.WESCAN_PAY.name,
            value: umfutils.fentoyuan(response["weScanpay"])
        });
        response["aliScanPay"] && result.push({
            title: constants.ProfitTypes.ALISCAN_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.ALISCAN_PAY.name,
            value: umfutils.fentoyuan(response["aliScanPay"])
        });
        response["idAuthPay"] && result.push({
            title: constants.ProfitTypes.IDAUTH_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.IDAUTH_PAY.name,
            value: umfutils.fentoyuan(response["idAuthPay"])
        });
        response["bCardVerifyPay"] && result.push({
            title: constants.ProfitTypes.BCARD_VERIFY_PAY.detailTitle + "(元)",
            tag: constants.ProfitTypes.BCARD_VERIFY_PAY.name,
            value: umfutils.fentoyuan(response["bCardVerifyPay"])
        });
    }
    return result;
}